<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<title>Say Good Bye</title>
	<script language="JavaScript">
		function checkEmail()
		{
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var email = document.mainForm.email.value;
			if (!filter.test(email)) 
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function sayGoodbye()
		{
			var name = "Anonymous";
			if(document.mainForm.userName.value != "")
			{
				name = document.mainForm.userName.value;
			}
			
			if(!checkEmail())
			{
				alert("Please enter a valid email");
			}
			else
			{
				alert("Good Bye, " + name)
			}
		}
	</script>
</head>
	
<body onunload="sayGoodbye()">
	<form name="mainForm" action="" method="post">
		Enter Your Name: <input type="text" name="userName" />
		<br />
		Enter Your Email: <input type="text" name="email" />
	</form>
</body>
</html>